function [fff,avg_VoL,avg_savings_rate,cry_cro_ratio]=calibrate_params(calib_guess,par,mpar,Y,utily,utilo,grid,U,fminbnd_options)


par.z=(calib_guess(1));
par.omega0=(calib_guess(2))*100;
par.omega1=(calib_guess(3));


global V_ini;

for flag=1:1:2
    V=V_ini(:,flag);
    I=0;mu=0;solflag=1;
    dist=9999;count=1;tic;
    dist_V = @(V)(V-VFI_update_spline(V,Y,utily,utilo,par,mpar,grid,U,flag,solflag,I,mu,[],[],[],[],[],[],fminbnd_options));
    while dist(count)>mpar.crit_run1
        count = count+1;
        DV    = dist_V(V);
        dist(count) = max(abs(DV(:))); % Calculate distance between old guess and update
        V     = V-DV;
    end
    Vsol=V;
    [~,bprimesol]=VFI_update_spline(Vsol,Y,utily,utilo,par,mpar,grid,U,flag,solflag,I,mu,[],[],[],[],[],[],fminbnd_options);
    csol=par.w+(1+par.r)*grid.b(:)-bprimesol;
    
    if     flag==1, U.ro=Vsol; bprime.ro=bprimesol;c.ro=csol;distF.ro=dist;
    elseif flag==2, U.ry=Vsol; bprime.ry=bprimesol;c.ry=csol;distF.ry=dist;
    end
end

%Calc. value of life and print out results to report in paper
muc_ro=(U.ro(par.grid_b_old_assets_idx)-par.z)^par.rho*(1-par.betta)*c.ro(par.grid_b_old_assets_idx)^(-par.rho);
VoL_old_assets_millions=U.ro(par.grid_b_old_assets_idx)/muc_ro/1000000;
muc_ry=(U.ry(par.grid_b_young_assets_idx)-par.z)^par.rho*(1-par.betta)*c.ry(par.grid_b_young_assets_idx)^(-par.rho);
VoL_young_assets_millions=U.ry(par.grid_b_young_assets_idx)/muc_ry/1000000;

cry_cro_ratio=c.ry(par.grid_b_young_assets_idx)/c.ro(par.grid_b_old_assets_idx);
savings_rate_ro=(par.w+par.r*grid.b(par.grid_b_old_assets_idx)-c.ro(par.grid_b_old_assets_idx))/(par.w+par.r*grid.b(par.grid_b_old_assets_idx));
savings_rate_ry=(par.w+par.r*grid.b(par.grid_b_young_assets_idx)-c.ry(par.grid_b_young_assets_idx))/(par.w+par.r*grid.b(par.grid_b_young_assets_idx));
avg_savings_rate=par.sy_shr*savings_rate_ry+(1-par.sy_shr)*savings_rate_ro;
avg_VoL=par.sy_shr*VoL_young_assets_millions+(1-par.sy_shr)*VoL_old_assets_millions;


%data targets:
%VoL: 890k, i.e. 0.89mill
%ratio of cons young&old, 1.18
%avg_savings rate, 6.7%


fff(1)=(0.89-avg_VoL)/0.89;
fff(2)=100*(0.067-avg_savings_rate)/0.067;
fff(3)=(1.18-cry_cro_ratio)/1.18;

